package com.st.buy.content.controller;

import com.st.buy.content.service.ContentCategoryService;
import com.st.buy.pojo.TbContent;
import com.st.buy.pojo.TbContentCategory;
import com.st.buy.util.pojo.BuyResult;
import com.st.buy.util.pojo.EasyUITreeNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 张双虎
 */
@RestController
public class ContentCategoryController {
    @Autowired
    private ContentCategoryService contentCategoryService;

    @RequestMapping("/contentCategory/list")
    public List<EasyUITreeNode> queryByPid(long pid){
        return contentCategoryService.queryCatByPid(pid);
    }

    @RequestMapping("/contentCategory/delete")
    public String delete(long catId){
        contentCategoryService.delete(catId);
        return "ok";
    }

    @RequestMapping("/contentCategory/update")
    public String update(@RequestBody TbContentCategory contentCategory){
        contentCategoryService.update(contentCategory);
        return "ok";
    };

    @RequestMapping("/contentCategory/save")
    public BuyResult save(@RequestBody TbContentCategory contentCategory){
        contentCategoryService.save(contentCategory);
        BuyResult buyResult = BuyResult.ok();
        buyResult.setData(contentCategory);//将保存后的对象直接设置到BuyResult
        return buyResult;
    }
}
